home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / CDEF-DeBugger 2.0 ƒ / Error.c < prev    next >
Text File  |  1995-05-31  |  3KB  |  93 lines

  1. // this file needs "errorIcon.r" to work
  2. // use this to report an error to the user.  Better used for debugging, but it could be modified
  3. // any way you see fit. Uses the icon provided in "errorIcon.r"
  4.  
  5. // prototypes
  6. void    ReportError( Str255    errorMsg );
  7. Boolean    CompareStr( Str255 srcA, Str255 srcB );
  8.  
  9. // globals
  10. extern Main        myMain;
  11.  
  12. /******************************************************************************
  13.  
  14.   A simple procedure for reporting errors.
  15.   
  16. *******************************************************************************/
  17. void    ReportError( Str255    errorMsg )
  18. {
  19.     short            maxStrSize, iconID, winHorz, winVert, strWidth;
  20.     Rect            theRect;
  21.     GrafPtr            thePort;
  22.     Point            localPt;
  23.     
  24.     
  25.     // store the current port and set up some intial variables
  26.     GetPort( &thePort );
  27.     
  28.     // make sure the error string isn't to large.
  29.     if( errorMsg[0] > 128 ) {
  30.         errorMsg[0] = 128;
  31.     }
  32.     
  33.     // grab our icon dude.
  34.     myMain.icon = GetCIcon( 32000 );
  35.     HLock( (Handle)myMain.icon );
  36.     
  37.     // position the window in global coordinates to center on the main screen.
  38.     SetRect( &theRect, 0, 0, 400, 200 );
  39.     myMain.error = NewCWindow( nil, &theRect, "\p", FALSE, dBoxProc, (WindowPtr)-1, false, ERROR_WINDOW );
  40.     SetPort( myMain.error );
  41.     
  42.     // set the text stuff up
  43.     TextFont( 9 );
  44.     TextSize( 9 );
  45.     TextFace( 0 );
  46.     strWidth = StringWidth( errorMsg );
  47.     
  48.     // add the size of our icon and the space between it and our text and space along the
  49.     // window frame. we will use this to size our window.
  50.     strWidth += 32 + 14 + 28;
  51.     
  52.     // make sure that it's not to small. just in case.
  53.     if( strWidth < 100 ) {
  54.         strWidth = 100;
  55.     }
  56.     
  57.     // no let's resize our window to fit the size.
  58.     winHorz = ( qd.screenBits.bounds.right - qd.screenBits.bounds.left ) / 2;
  59.     winVert    = ( qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ) / 3;
  60.     SizeWindow( myMain.error, strWidth, 60, TRUE );
  61.     MoveWindow( myMain.error, winHorz - (strWidth / 2), winVert, TRUE );
  62.     ShowWindow( myMain.error );
  63.     
  64.     // draw our nifty icon dude.
  65.     SetRect( &theRect, (*myMain.error).portRect.left + 14, (*myMain.error).portRect.top + 14,
  66.                        (*myMain.error).portRect.left + 46, (*myMain.error).portRect.top + 46 );
  67.     PlotCIcon( &theRect, myMain.icon );
  68.     
  69.     // draw the error message.
  70.     MoveTo( 60, 25 );
  71.     TextFace( 1 );
  72.     DrawString( "\pError Report:" );
  73.     TextFace( 0 );
  74.     MoveTo( 60, 40 );
  75.     DrawString( errorMsg );
  76.     
  77.     // store the message for later retrieval
  78.     BlockMove( &errorMsg[0], &myMain.errMsg[0], errorMsg[0] );
  79.     
  80.     // do a system beep just for the excitement of things.
  81.     SysBeep( 1 );
  82.     
  83.     // just create a little loop untill the user presses the mouse button
  84.     do {
  85.     } while ( !Button());
  86.     
  87.     // Handle anything we might of done.
  88.     HUnlock( (Handle)myMain.icon );
  89.     DisposCIcon( myMain.icon );
  90.     DisposeWindow( myMain.error );
  91.     
  92.     ExitToShell();
  93. }